<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
Ext.onReady(function() {
	
	Ext.QuickTips.init();
	
	Ext.define('Student', { 
        extend: 'Ext.data.Model', 
        // fields定义字段和数据类型 
        fields: ['id', 'displayName'] 
    });
	
	Ext.define('Class', {
		extend: 'Ext.data.Model',
		fields: ['id','className']
	});
	
	Ext.define('Week',{
    	extend: 'Ext.data.Model',
    	fields: ['id','week']
    });
    
    var weekstates=[{'id':'1','week':'W1（第一周）'},
                    {'id':'2','week':'W2（第二周）'},
                    {'id':'3','week':'W3（第三周）'},
                    {'id':'4','week':'W4（第四周）'},
                    {'id':'5','week':'W5（第五周）'},
                    {'id':'6','week':'W6（第六周）'},
                    {'id':'7','week':'W7（第七周）'},
                    {'id':'8','week':'W8（第八周）'},
                    {'id':'9','week':'W9（第九周）'},
                    {'id':'10','week':'W10（第十周）'},
                    {'id':'11','week':'W11（第十一周）'},
                    {'id':'12','week':'W12（第十二周）'}];
	
	var studentstore=Ext.create('Ext.data.Store', {
        model: 'Student', 
        autoLoad: true,
        //使用ajax代理 
        proxy: { 
            type: 'ajax', 
            url: '../service/class1_findselected',
            //Reader 解码json数据 
            reader: { 
                type: 'json', 
                root: 'students', 
                total: 'total'
            }
        }
    });
	
	var classstore=Ext.create('Ext.data.Store', {
		model: 'Class',
		autoload: true,
		proxy: {
			type: 'ajax',
			url: '../service/class1_all',
			reader: {
				type: 'json',
				root: 'root',
				total: 'total'
			}
		}
	});

    var weekstore=Ext.create('Ext.data.Store', {
        autoDestroy: true,
        model: 'Week',
        data: weekstates
    });
	
	var makeupform=Ext.widget({
		 	xtype: 'form',
	        layout: 'form',
	        renderTo:'makeupform',
	        frame:true,
	        fieldDefaults: {
	            msgTarget: 'qtip',
	            labelWidth: 80
	        },
	        defaultType: 'textfield',
	        items: [
	        	Ext.create('Ext.form.field.ComboBox', {
	        	    displayField: 'className',
	        	    store: classstore,
	        	    fieldLabel:'选择班级',
	        	    valueField: 'id',
	                margin: 5,
	                name: 'makeup.classId',
	        	    id: 'classid',
	                allowBlank: false,
	        	    listeners: {
	        	    	select: function(comb, records) {
	        	    		Ext.each(records, function(record) {
	        	    			Ext.getCmp('studentid').reset();
	            	    		studentstore.load({
	                    			params: {
	                    		        id: record.data.id
	                    		    },
	                    		});
	        	    		});
	        	    	}
	        	    }
	        	}),Ext.create('Ext.form.field.ComboBox', {
	        	    displayField: 'displayName',
	        	    store: studentstore,
	        	    fieldLabel:'学生姓名',
	        	    valueField: 'id',
	        	    name: 'makeup.studentId',
	                margin: 5,
	        	    id: 'studentid',
	                allowBlank: false,
	        	    listeners: {
	        	    	select: function(comb, records) {
	        	    		Ext.each(records, function(record) {
	        	    		});
	        	    	}
	        	    }
	        	}),Ext.create('Ext.form.field.ComboBox', {
	        	    displayField: 'week',
	        	    store: weekstore,
	        	    fieldLabel:'周数',
	                margin: 5,
	        	    valueField: 'id',
	                queryMode: 'local',
	                name: 'makeup.week',
	        	    id: 'week',
	                allowBlank: false,
	        	    listeners: {
	        	    	select: function(comb, records) {
	        	    		Ext.each(records, function(record) {
	        	    		});
	        	    	}
	        	    }
	        }),{
	        	id:'makeupTime',
	            fieldLabel: '补课时间',
	            xtype: 'datefield',
                format: 'Y-m-d', 
	            name: 'makeup.makeupTime',
	            allowBlank: false
	        }],

       buttons: [{
           text: '保存',
           handler: function() {
        	   this.up('form').getForm().submit({  
                   url : '../service/makeup_add',//请求的url地址  
                   method:'post',//请求方式
                   success:function(form,action){//加载成功的处理函数  
	                   	Ext.Msg.alert('提示', action.result.msg);
                   		Ext.getCmp('makeupaddform').close();
              		},
                   failure:function(form,action){//加载成功的处理函数  
 		        		Ext.Msg.alert('提示', action.result.msg); 
  		        	}
               });
       		}
       },{
       	text: '重置',
           handler: function() {
           	this.up('form').getForm().reset();
           }
       }]
   });
});
</script>
</head>
<body>
<div id="makeupform"></div>
</body>
</html>